package com.joyplus.report.business.controller;

import com.joyplus.report.business.domain.MdCampaignSupplement;
import com.joyplus.report.business.qo.MdCampaignSupplementQO;
import com.joyplus.report.business.service.MdCampaignSupplementService;
import com.joyplus.report.core.Result;
import com.joyplus.report.core.ResultGenerator;
import com.github.pagehelper.PageInfo;
import com.mongodb.DBObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

/**
 * Controller
 *
 * @author jeff
 * @date 2018-05-31
 */
@RestController
@Api(tags = "")
@RequestMapping("/md/campaign/supplement")
public class MdCampaignSupplementController {

  @Resource
  private MdCampaignSupplementService mdCampaignSupplementService;


  @GetMapping("/s2sdetail")
  @ApiOperation(value = "查询详情", response = MdCampaignSupplement.class, notes = "查询详情")
  @ApiImplicitParams({
      @ApiImplicitParam(required = true, name = "id", value = "主键ID", paramType = "query", dataType = "long")
  })
  public Result detail(@RequestParam Integer id) {
    MdCampaignSupplement mdCampaignSupplement = mdCampaignSupplementService.getById(id);

    List<DBObject> planCampaign = mdCampaignSupplementService.getPlanCampaign(id);
    List<DBObject> s2SRealCampaign = mdCampaignSupplementService.getS2SRealCampaign(id);

    List<DBObject> c2SRealCampaign = mdCampaignSupplementService.getC2SRealCampaign(id);

    Map<Object, Object> objectObjectMap = new HashMap<>();
    objectObjectMap.put("planCampaign", planCampaign);
    objectObjectMap.put("mdCampaignSupplement", mdCampaignSupplement);
    objectObjectMap.put("s2SRealCampaign", s2SRealCampaign);
    //objectObjectMap.put("c2SRealCampaign",c2SRealCampaign);

    return ResultGenerator.genSuccessResult(objectObjectMap);
  }


  @GetMapping("/c2sdetail")
  @ApiOperation(value = "查询详情", response = MdCampaignSupplement.class, notes = "查询详情")
  @ApiImplicitParams({
      @ApiImplicitParam(required = true, name = "id", value = "主键ID", paramType = "query", dataType = "long")
  })
  public Result c2sdetail(@RequestParam Integer id) {
    MdCampaignSupplement mdCampaignSupplement = mdCampaignSupplementService.getById(id);
    List<DBObject> planCampaign = mdCampaignSupplementService.getPlanCampaign(id);
    //List<DBObject> s2SRealCampaign = mdCampaignSupplementService.getS2SRealCampaign(id);
    List<DBObject> c2SRealCampaign = mdCampaignSupplementService.getC2SRealCampaign(id);
    Map<Object, Object> objectObjectMap = new HashMap<>();
    objectObjectMap.put("planCampaign", planCampaign);
    objectObjectMap.put("mdCampaignSupplement", mdCampaignSupplement);
    objectObjectMap.put("c2SRealCampaign", c2SRealCampaign);
    //objectObjectMap.put("c2SRealCampaign",c2SRealCampaign);

    return ResultGenerator.genSuccessResult(objectObjectMap);
  }


  @GetMapping("/listPage")
  @ApiOperation(value = "分页查询", response = MdCampaignSupplement.class, notes = "分页查询")
  @ApiImplicitParams({
      @ApiImplicitParam(required = true, name = "pageSize", value = "每页显示数量", paramType = "query", dataType = "int"),
      @ApiImplicitParam(required = true, name = "pageNum", value = "第几页", paramType = "query", dataType = "int"),
      @ApiImplicitParam(required = false, name = "campaignName", value = "搜索key", paramType = "query", dataType = "String")
  })
  public Result listPage(MdCampaignSupplementQO mdCampaignSupplementQO) {
    PageInfo<MdCampaignSupplement> p = mdCampaignSupplementService.findPage(mdCampaignSupplementQO);
    return ResultGenerator.genSuccessResult(p);
  }


  @GetMapping("/list")
  @ApiOperation(value = "分页查询", response = MdCampaignSupplement.class, notes = "分页查询")
  public Result list(MdCampaignSupplementQO mdCampaignSupplementQO) {
    List<MdCampaignSupplement> p = mdCampaignSupplementService.findAll();
    return ResultGenerator.genSuccessResult(p);
  }

}
